package ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;

import bdd.Traitement;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

public class fenetreSave extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JButton sauvegarder = new JButton("Sauvegarder");
	private JLabel lblNomDuScnario = new JLabel("Nom du sc\u00E9nario :");
	private Traitement traitement = new Traitement();
	private int tailleGrille=0;
	private int nbPas=0;
	private int vitesse=0;
	private String arbres[][];


	/**
	 * Create the frame.
	 */
	public fenetreSave(int tailleGrillep,int nbPasp,int vitessep, String arbresp[][]) {
		
		this.tailleGrille=tailleGrillep;
		this.nbPas=nbPasp;
		this.vitesse=vitessep;
		this.arbres=arbresp;
		setResizable(false);
		this.setTitle("J-SIM Forest - Sauvegarde");
		this.setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 312, 138);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textField = new JTextField();
		textField.setBounds(10, 35, 276, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		sauvegarder.setBounds(59, 66, 187, 23);
		contentPane.add(sauvegarder);
		

		lblNomDuScnario.setBounds(10, 11, 276, 14);
		contentPane.add(lblNomDuScnario);
		this.setVisible(true);
		
		sauvegarder.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				String nomScenario = textField.getText();
				try {
					if(nomScenario==null || nomScenario.length()==0){
						dispose();
					}
					else{
						traitement.ajouterScenario(nomScenario,tailleGrille, nbPas, vitesse, arbres);
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			dispose();
			}
		});

	}
}
